from data.morse_data import morse_dict

A = morse_dict['A']
print(A)


def init_str(str):
    str_upper = str.upper()
    return str_upper


def get_morse_code(str):
    code = ""
    str = str.strip()
    if len(str) != 0:
        str = str.upper()
        for item in str:
            try:
                item_code = morse_dict[item] + " "
            except KeyError:
                # print("字符不支持")
                return "字符不支持"
            code += item_code
        return code.strip()
    else:
        return


def get_word(str):
    word = ""
    str = str.strip()
    if len(str) != 0:
        code = str.split(" ")
        print(code)
        for item in code:
            decode_success = False
            for key, value in morse_dict.items():
                if item == value:
                    decode_success = True
                    word += key
            if not decode_success:
                return "莫斯密码有误"
    else:
        return
    return word


a = "《"
morse_code = get_morse_code(a)
print(morse_code)

word = get_word(".- ... -.. ..-. .-- . .-. ")
print(word)
